package cn.itcast.bos.service.base.Impl;

import java.util.List;
import java.util.Set;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.CourierRepository;
import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.service.base.CourierService;
@Service
@Transactional
public class CourierServiceImpl implements CourierService {
	@Autowired
	private CourierRepository courierRepository;

	@Override
	public void save(Courier courier) {
		// TODO Auto-generated method stub
		courierRepository.save(courier);
	}

	@Override
	public Page<Courier> courierFindAll(Specification<Courier> sa,Pageable pageAble) {
		// TODO Auto-generated method stub
		Page<Courier> findAll = courierRepository.findAll(sa,pageAble);
		return findAll;
	}

	@Override
	public void delBatch(String[] arr) {
		// TODO Auto-generated method stub
		for(String str : arr){
			int id = Integer.parseInt(str);
			courierRepository.delBatch(id);
		}
	}

	@Override
	public List<Courier> courierFindAll1() {
		// TODO Auto-generated method stub
		Specification<Courier> sf = new Specification<Courier>() {
			
			//	Predicate p = null;
				@Override
				public Predicate toPredicate(Root<Courier> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
					Predicate p = cb.isEmpty(root.get("fixedAreas").as(Set.class));
					return p;
				}
				
			};
			List<Courier> findAll = courierRepository.findAll(sf);
			return findAll;
	}



	@Override
	public Courier findOne(Integer courierId) {
		// TODO Auto-generated method stub
		return null;
	}


	

}
